<%@page pageEncoding="UTF-8" language="java" %>
<%@ include file="/commons/global.jsp"%>
<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="Bookmark" href="favicon.ico" >
<link rel="Shortcut Icon" href="favicon.ico" />
<script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/respond.min.js"></script>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/h-ui.admin/css/style.css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/css/style.css" />
<style type="text/css">
	.table-sort tr td{
	    text-align: center;
	}
	.dataTable td.sorting_1{
		background-color: inherit;
	}
	.mt_right {
    width: 100%;
}
</style>
</head>
<body>
    <article class="cl pd-20">
        <form  method="post" action="<%=request.getContextPath()%>/trainPlan/add" id="trainPlanForm" class="form form-horizontal" >
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>届数：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="" id="enterterm" name="enterterm">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>培养方案名称：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="" id="trainPlanName" name="trainPlanName">
                    <input type="hidden" value="${currentUser.id }" name = "builderId" id="builderId"/>
                    <input name="code2" class="input-text" id="code2" value= "已经存在" readonly style="color:#F00;" hidden />
                    <input type="hidden" value="0" name = "status" id="status"/>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>专业名称：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="${major.name }" placeholder="" id="majorName" name="majorName"readonly>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>专业编号：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="${major.id }" placeholder="" id="majorCode" name="majorCode" readonly>
                </div>
            </div>
             <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>学制：</label>
                <div class="formControls col-xs-8 col-sm-9"> <span class="select-box" style="width:250px;">
					<select  class="select" id="term" name="term">
						<option value="">---请选择学制---</option>
						<option value="4">---4年---</option>
						<option value="5">---5年---</option>
					</select>
				</span> 
				</div>
            </div>
             <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>学期：</label>
                <div class="formControls col-xs-8 col-sm-9"> <span class="select-box" style="width:250px;">
					<select  class="select" id="term1" name="term1">
							<option value="">---请选择学期---</option>
							<option value="4">---8学期---</option>
							<option value="5">---10学期---</option>
						</select>
				</span> 
				</div>
            </div>
             <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>学分：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="" id="score1" name="score1">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">培养目标：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <textarea cols="" rows="" class="textarea" name="goal" id="goal" ></textarea>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">毕业生应获得以下知识与能力：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <textarea cols="" rows="" class="textarea" name="ability" id="ability" ></textarea>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">所学课程：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <textarea cols="" rows="" class="textarea" name="course" id="course" ></textarea>
                </div>
            </div>
	          <div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">教学进程：</label>
				<div class="formControls col-xs-8 col-sm-9">
				<div class="cl pd-5 bg-1 bk-gray mt-20">
					<span class="l"> <a href="javascript:;" id="add" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加</a> </span>
				</div>
					<table class="table table-border table-bordered table-bg table-hover table-sort" id = "schedule">
						<thead>
							<tr class="text-c">
								<th>课程名</th>
								<th>课程编码</th>
								<th>学分</th>
								<th>理论</th>
								<th>实践</th>
								<th>自主</th>
								<th>总计</th>
								<th>考核方式</th>
								<th>第几学期上</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<tr  id="add_info">
								<td>
									<input name="courseName" type="text" placeholder="课程名称"/>
								</td>
								<td>
									<input name="courseCode" type="text" placeholder="课程编号"/>
								</td>
								<td>
									<input id="score" name="score" type="text" placeholder="学分"/>
								</td>
								<td>
									<input id="theory" name="theory" type="text" placeholder="理论"/>
								</td>
								<td>
									<input id="experiment" name="experiment" type="text" placeholder="实践"/>
								</td>
								<td>
									<input id="selfmaster" name="selfmaster" type="text" placeholder="自主"/>
								</td>
								<td>
									<input id="sum" name="sum" type="text" placeholder="总计"/>
								</td>
								<td>
									<input id="examtype" name="examtype" type="text" placeholder="考核方式"/>
								</td>
								<td>
									<input id="termth" name="termth" type="text" placeholder="第几学期上"/>
								</td>
								<td>
									 <a href="javascript:;" onclick='deleteCurrentRow(this);'>删除</a>
								</td>
							</tr>
						</tbody>
					</table>
				</div>
			</div>
            <div class="row cl">
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-6">
					<button id="courseAdd" class="btn btn-primary radius" type="button"><i class="Hui-iconfont">&#xe632;</i> 保存</button>
					<button id="cancel" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
				</div>
			</div>
        </form>
    </article>
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/jquery/1.9.1/jquery.min.js"></script> 
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/layer/2.4/layer.js"></script> 
<%-- 	<script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/icheck/jquery.icheck.min.js"></script>  --%>
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/jquery.validation/1.14.0/messages_zh.js"></script> 
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/h-ui/js/H-ui.js"></script> 
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/h-ui.admin/js/H-ui.admin.page.js"></script> 
	<script type="text/javascript">
		/* $("#add").click(function() {
			$(".no_info").css("display","none");
			$("#add_info").css("display","");
		}); */
		$("#trainPlanName").blur(function(){
		    var trainPlanName = $(this).val();
		     //用ajax去数据库匹配，
		    $.ajax({
		        url:"<%=request.getContextPath()%>/trainPlan/codeCheck", 
		        async : false,
				type : "post",
				dataType : "json",
				data : {
				    "trainPlanName" : trainPlanName 
				},
				success : function(data) {
					if (data.msg != "") {
						$("#code2").show();
						$("#trainPlanName").val("");
					} else {
						$("#code2").css('display','none');
					}
				}
		    });    
		})
		
		$("#add").click(function() {
			document.getElementById("schedule").appendChild(document.getElementById("add_info").cloneNode(true));
      	});
		function deleteCurrentRow(obj){
	            var tr=obj.parentNode.parentNode;
	            var tbody=tr.parentNode;
				if(tbody.rows.length>1) {
		            tbody.removeChild(tr);
				}
        }
		$("#cancel").click(function(){
			parent.layer.close(parent.index);
		});
		$("#code").blur(function(){
		    var code = $(this).val();
		     //用ajax去数据库匹配，
		    $.ajax({
		        url:"<%=request.getContextPath()%>/manage/course/codeCheck", 
		        async : false,
				type : "post",
				dataType : "json",
				data : {
				    "code" : code 
				},
				success : function(data) {
					if (data.msg != "") {
						$("#code2").show();
						$("#code").val("");
					} else {
						$("#code2").css('display','none');
					}
				}
		    });    
		})
		
		function courseAdd(){
			var data = $("#trainPlanForm").serialize();
			$.ajax({
				url: $("#trainPlanForm").attr("action"),
				data: data,
				type: "post",
				dataType: "json",
				success: function(result){
					if(result.success){
						top.layer.open({
							icon: 1,
							content: '保存成功！',
							time: 1500
						});
						$(window.parent.document).find("#pageForm").submit();
						parent.layer.close(parent.index);
					}else{
						top.layer.open({
							icon: 2,
							content: '保存失败！',
							time: 1500
						});
					}
				}
			});
		}
		$(function(){
			
			/* 校验 */
			var trainPlanForm;
			
			$("#courseAdd").click(function(){
				if(!trainPlanForm.form()){
					return false;
				}else{
					courseAdd();
				}
			});
			
			trainPlanForm = $("#trainPlanForm").validate({
				"rules":{
					"enterterm":{
						"required":true
					},
					"trainPlanName":{
						"required":true
					},
					"majorName":{
						"required":true
					},
					"majorCode":{
						"required":true
					},
					"term":{
						"required":true
					},
					"score1":{
						"required":true
					},
				},
				"messages":{
					"enterterm":{
						"required":"届数不能为空！"
					},
					"trainPlanName":{
						"required":"方案名称不能为空！"
					},
					"majorName":{
						"required":"专业名称不能为空！"
					},
					"majorCode":{
						"required":"专业编号不能为空！"
					},
					"term":{
						"required":"学制不能为空！"
					},
					"score1":{
						"required":"学制不能为空！"
					},
				}
			});
		});
	</script>
</body>
</html>
